<script type="text/javascript">
  initFilter();
</script>
<h4>
  <span>Filter</span>
  <a class="pull-right" title="Reset" onclick="resetFilter();">&nbsp;<i class="fa fa-refresh"></i></a>
</h4>
<form class="form" method="get" action="<?php echo $filter['filter_form_path']; ?>" id="filter_form">
  <input type="hidden" name="sort_by" value="<?php echo $filter['filter_sort_by']; ?>"/>
  <input type="hidden" name="sort_order" value="<?php echo $filter['filter_sort_order']; ?>"/>
  <?php if (!empty($filter['filter_items'])) { ?>
    <div class="panel panel-default" id="item_box">
      <div class="panel-heading">
        <a class="accordion-toggle <?php if (empty($filter['filter_items_sel'])) { ?> collapsed <?php } ?>" data-toggle="collapse" href="#collapse_item"><b>Item</b></a>
        <div class="pull-right">
          <?php if (count($filter['filter_items']) == count($filter['filter_items_sel'])) { ?>
            <a title="Uncheck all" onclick="selectAllCheckbox('item_box', false, true);"><i class="fa fa-check-square-o"></i></a>
          <?php } else { ?>
            <a title="Check all" onclick="selectAllCheckbox('item_box', true, true);"><i class="fa fa-plus-square-o"></i></a>
          <?php } ?>
          <a title="Clear" onclick="selectAllCheckbox('item_box', false, true);"><i class="fa fa-minus-square-o"></i></a>
        </div>
      </div>
      <div class="panel-body panel-collapse collapse sidebar-panel-body <?php if (empty($filter['filter_items_sel'])) { ?> in <?php } ?>" id="collapse_item">
        <?php if (count($filter['filter_items']) > 10) { ?>
          <ol class="nav nav-list">
            <li>
              <input class="form-control" type="text" placeholder="Search Items" onkeyup="searchFilterBox(this, 'item_box');"/>
            </li>
          </ol>
          <hr>
        <?php } ?>
        <?php foreach ($filter['filter_items'] as $item) { ?>
          <ul class="nav nav-list">
            <li>
              <label class="checkbox-inline width-full">
                <input type="checkbox" value="<?php echo $item['item_id']; ?>" name="items[]" <?php if (in_array($item['item_id'], $filter['filter_items_sel'])) { ?> checked="true" <?php } ?>>
                <a><?php echo $item['item_name']; ?></a>
              </label>
            </li>
          </ul>
        <?php } ?>
        <?php if (count($filter['filter_item_types']) > 10) { ?>
          <ol class="nav nav-list">
            <li>
              &nbsp;
            </li>
          </ol>
        <?php } ?>
      </div>
    </div>
  <?php } ?>
  <?php if (!empty($filter['filter_item_types'])) { ?>
    <div class="panel panel-default" id="item_type_box">
      <div class="panel-heading">
        <a class="accordion-toggle <?php if (empty($filter['filter_item_types_sel'])) { ?> collapsed <?php } ?>" data-toggle="collapse" href="#collapse_item_type"><b>Type</b></a>
        <div class="pull-right">
          <?php if (count($filter['filter_item_types']) == count($filter['filter_item_types_sel'])) { ?>
            <a title="Uncheck all" onclick="selectAllCheckbox('item_type_box', false, true);"><i class="fa fa-check-square-o"></i></a>
          <?php } else { ?>
            <a title="Check all" onclick="selectAllCheckbox('item_type_box', true, true);"><i class="fa fa-plus-square-o"></i></a>
          <?php } ?>
          <a title="Clear" onclick="selectAllCheckbox('item_type_box', false, true);"><i class="fa fa-minus-square-o"></i></a>
        </div>
      </div>
      <div class="panel-body panel-collapse collapse sidebar-panel-body <?php if (empty($filter['filter_item_types_sel'])) { ?> in <?php } ?>" id="collapse_item_type">
        <?php if (count($filter['filter_item_types']) > 10) { ?>
          <ol class="nav nav-list">
            <li>
              <input class="form-control" type="text" placeholder="Search Item Types" onkeyup="searchFilterBox(this, 'item_type_box');"/>
            </li>
          </ol>
          <hr>
        <?php } ?>
        <?php foreach ($filter['filter_item_types'] as $item_type) { ?>
          <ul class="nav nav-list">
            <li>
              <label class="checkbox-inline width-full">
                <input type="checkbox" value="<?php echo $item_type['item_type_id']; ?>" name="item_types[]" <?php if (in_array($item_type['item_type_id'], $filter['filter_item_types_sel'])) { ?> checked="true" <?php } ?>>
                <a><?php echo $item_type['item_type_name']; ?></a>
              </label>
            </li>
          </ul>
        <?php } ?>
        <?php if (count($filter['filter_item_types']) > 10) { ?>
          <ol class="nav nav-list">
            <li>
              &nbsp;
            </li>
          </ol>
        <?php } ?>
      </div>
    </div>
  <?php } ?>
  <?php if (!empty($filter['filter_item_extras'])) { ?>
    <div class="panel panel-default" id="item_extra_box">
      <div class="panel-heading">
        <a class="accordion-toggle <?php if (empty($filter['filter_item_extras_sel'])) { ?> collapsed <?php } ?>" data-toggle="collapse" href="#collapse_item_extra"><b>Extra</b></a>
        <div class="pull-right">
          <?php if (count($filter['filter_item_extras']) == count($filter['filter_item_extras_sel'])) { ?>
            <a title="Uncheck all" onclick="selectAllCheckbox('item_extra_box', false, true);"><i class="fa fa-check-square-o"></i></a>
          <?php } else { ?>
            <a title="Check all" onclick="selectAllCheckbox('item_extra_box', true, true);"><i class="fa fa-plus-square-o"></i></a>
          <?php } ?>
          <a title="Clear" onclick="selectAllCheckbox('item_extra_box', false, true);"><i class="fa fa-minus-square-o"></i></a>
        </div>
      </div>
      <div class="panel-body panel-collapse collapse sidebar-panel-body <?php if (empty($filter['filter_item_extras_sel'])) { ?> in <?php } ?>" id="collapse_item_extra">
        <?php if (count($filter['filter_item_extras']) > 10) { ?>
          <ol class="nav nav-list">
            <li>
              <input class="form-control" type="text" placeholder="Search Item Extras" onkeyup="searchFilterBox(this, 'item_extra_box');"/>
            </li>
          </ol>
          <hr>
        <?php } ?>
        <?php foreach ($filter['filter_item_extras'] as $item_extra) { ?>
          <ul class="nav nav-list">
            <li>
              <label class="checkbox-inline width-full">
                <input type="checkbox" value="<?php echo $item_extra['item_extra_id']; ?>" name="item_extras[]" <?php if (in_array($item_extra['item_extra_id'], $filter['filter_item_extras_sel'])) { ?> checked="true" <?php } ?>>
                <a><?php echo $item_extra['item_extra_name']; ?></a>
              </label>
            </li>
          </ul>
        <?php } ?>
        <?php if (count($filter['item_extra_name']) > 10) { ?>
          <ol class="nav nav-list">
            <li>
              &nbsp;
            </li>
          </ol>
        <?php } ?>
      </div>
    </div>
  <?php } ?>
  <?php if (!empty($filter['filter_brands'])) { ?>
    <div class="panel panel-default" id="brand_box">
      <div class="panel-heading">
        <a class="accordion-toggle <?php if (empty($filter['filter_brands_sel'])) { ?> collapsed <?php } ?>" data-toggle="collapse" href="#collapse_brand"><b>Brand</b>&nbsp;(<?php echo count($filter['filter_brands']); ?>)</a>
        <div  class="pull-right">
          <?php if (count($filter['filter_brands']) == count($filter['filter_brands_sel'])) { ?>
            <a title="Uncheck all" onclick="selectAllCheckbox('brand_box', false, true);"><i class="fa fa-check-square-o"></i></a>
          <?php } else { ?>
            <a title="Check all" onclick="selectAllCheckbox('brand_box', true, true);"><i class="fa fa-plus-square-o"></i></a>
          <?php } ?>
          <a title="Clear" onclick="selectAllCheckbox('brand_box', false, true);"><i class="fa fa-minus-square-o"></i></a>
        </div>
      </div>
      <div class="panel-body panel-collapse collapse sidebar-panel-body <?php if (empty($filter['filter_brands_sel'])) { ?> in <?php } ?>" id="collapse_brand">
        <?php if (count($filter['filter_brands']) > 10) { ?>
          <ol class="nav nav-list">
            <li>
              <input class="form-control" type="text" placeholder="Search Brands" onkeyup="searchFilterBox(this, 'brand_box');"/>
            </li>
          </ol>
          <hr>
        <?php } ?>
        <?php foreach ($filter['filter_brands'] as $brand) { ?>
          <ul class="nav nav-list">
            <li>
              <label class="checkbox-inline width-full">
                <input type="checkbox" value="<?php echo $brand['brand_id']; ?>" name="brands[]" <?php if (in_array($brand['brand_id'], $filter['filter_brands_sel'])) { ?> checked="true" <?php } ?>>
                <a><?php echo $brand['brand_name']; ?></a>
              </label>
            </li>
          </ul>
        <?php } ?>
        <?php if (count($filter['filter_brands']) > 10) { ?>
          <ol class="nav nav-list">
            <li>
              &nbsp;
            </li>
          </ol>
        <?php } ?>
      </div>
    </div>
  <?php } ?>
  <?php if (!empty($filter['filter_brand_models'])) { ?>
    <div class="panel panel-default" id="brand_model_box">
      <div class="panel-heading">
        <a class="accordion-toggle <?php if (empty($filter['filter_brand_models_sel'])) { ?> collapsed <?php } ?>" data-toggle="collapse" href="#collapse_brand_model"><b>Model</b>&nbsp;(<?php echo count($filter['filter_brand_models']); ?>)</a>
        <div class="pull-right">
          <?php if (count($filter['filter_brand_models']) == count($filter['filter_brand_models_sel'])) { ?>
            <a title="Uncheck all" onclick="selectAllCheckbox('brand_model_box', false, true);"><i class="fa fa-check-square-o"></i></a>
          <?php } else { ?>
            <a title="Check all" onclick="selectAllCheckbox('brand_model_box', true, true);"><i class="fa fa-plus-square-o"></i></a>
          <?php } ?>
          <a title="Clear" onclick="selectAllCheckbox('brand_model_box', false, true);"><i class="fa fa-minus-square-o"></i></a>
        </div>
      </div>
      <div class="panel-body panel-collapse collapse sidebar-panel-body <?php if (empty($filter['filter_brand_models_sel'])) { ?> in <?php } ?>" id="collapse_brand_model">
        <?php if (count($filter['filter_brand_models']) > 10) { ?>
          <ol class="nav nav-list">
            <li>
              <input class="form-control" type="text" placeholder="Search Models" onkeyup="searchFilterBox(this, 'brand_model_box');"/>
            </li>
          </ol>
          <hr>
        <?php } ?>
        <?php foreach ($filter['filter_brand_models'] as $brand_model) { ?>
          <ul class="nav nav-list">
            <li>
              <label class="checkbox-inline width-full">
                <input type="checkbox" value="<?php echo $brand_model['brand_model_id']; ?>" name="brand_models[]" <?php if (in_array($brand_model['brand_model_id'], $filter['filter_brand_models_sel'])) { ?> checked="true" <?php } ?>>
                <a><?php echo $brand_model['brand_model_name']; ?></a>
              </label>
            </li>
          </ul>
        <?php } ?>
        <?php if (count($filter['filter_brand_models']) > 10) { ?>
          <ol class="nav nav-list">
            <li>
              &nbsp;
            </li>
          </ol>
        <?php } ?>
      </div>
    </div>
  <?php } ?>
  <?php if (!empty($filter['filter_price_ranges'])) { ?>
    <div class="panel panel-default" id="price_range_box">
      <div class="panel-heading">
        <a class="accordion-toggle <?php if (empty($filter['filter_price_ranges_sel'])) { ?> collapsed <?php } ?>" data-toggle="collapse" href="#collapse_price_range"><b>Price Range</b></a>
        <div class="pull-right">
          <?php if (count($filter['filter_price_ranges']) == count($filter['filter_price_ranges_sel'])) { ?>
            <a title="Uncheck all" onclick="selectAllCheckbox('price_range_box', false, true);"><i class="fa fa-check-square-o"></i></a>
          <?php } else { ?>
            <a title="Check all" onclick="selectAllCheckbox('price_range_box', true, true);"><i class="fa fa-plus-square-o"></i></a>
          <?php } ?>
          <a title="Clear" onclick="selectAllCheckbox('price_range_box', false, true);"><i class="fa fa-minus-square-o"></i></a>
        </div>
      </div>
      <div class="panel-body panel-collapse collapse sidebar-panel-body <?php if (empty($filter['filter_price_ranges_sel'])) { ?> in <?php } ?>" id="collapse_price_range">
        <?php foreach ($filter['filter_price_ranges'] as $price_range) { ?>
          <ul class="nav nav-list">
            <li>
              <label class="checkbox-inline width-full">
                <input type="checkbox" value="<?php echo $price_range['price_range_id']; ?>" name="price_ranges[]" <?php if (in_array($price_range['price_range_id'], $filter['filter_price_ranges_sel'])) { ?> checked="true" <?php } ?>>
                <a><?php echo $price_range['price_range_text']; ?></a>
              </label>
            </li>
          </ul>
        <?php } ?>
        <ul class="nav nav-list">
          <li>
            &nbsp;
          </li>
        </ul>
      </div>
    </div>
  <?php } ?>
  <div class="panel panel-default" id="condition_box">
    <div class="panel-heading">
      <a class="accordion-toggle <?php if (empty($filter['filter_condition_sel'])) { ?> collapsed <?php } ?>" data-toggle="collapse" href="#collapse_condition"><b>Condition</b></a>
      <div class="pull-right">
        <?php if (2 == count($filter['filter_condition_sel'])) { ?>
          <a title="Uncheck all" onclick="selectAllCheckbox('condition_box', false, true);"><i class="fa fa-check-square-o"></i></a>
        <?php } else { ?>
          <a title="Check all" onclick="selectAllCheckbox('condition_box', true, true);"><i class="fa fa-plus-square-o"></i></a>
        <?php } ?>
        <a title="Clear" onclick="selectAllCheckbox('condition_box', false, true);"><i class="fa fa-minus-square-o"></i></a>
      </div>
    </div>
    <div class="panel-body panel-collapse collapse sidebar-panel-body <?php if (empty($filter['filter_condition_sel'])) { ?> in <?php } ?>" id="collapse_condition">
      <ul class="nav nav-list col-sm-6 pull-right">
        <li>
          <label class="checkbox-inline width-full">
            <input type="checkbox" value="used" name="condition[]" <?php if (in_array('used', $filter['filter_condition_sel'])) { ?> checked="true" <?php } ?>>
            <a>Used</a>
          </label>
        </li>
      </ul>
      <ul class="nav nav-list col-sm-6 pull-right">
        <li>
          <label class="checkbox-inline width-full">
            <input type="checkbox" value="new" name="condition[]" <?php if (in_array('new', $filter['filter_condition_sel'])) { ?> checked="true" <?php } ?>>
            <a>New</a>
          </label>
        </li>
      </ul>
    </div>
  </div>
  <div class="panel panel-default" id="posted_by_box">
    <div class="panel-heading">
      <a class="accordion-toggle <?php if (empty($filter['filter_posted_by_sel'])) { ?> collapsed <?php } ?>" data-toggle="collapse" href="#collapse_posted_by"><b>By</b></a>
      <div class="pull-right">
        <?php if (2 == count($filter['filter_posted_by_sel'])) { ?>
          <a title="Uncheck all" onclick="selectAllCheckbox('posted_by_box', false, true);"><i class="fa fa-check-square-o"></i></a>
        <?php } else { ?>
          <a title="Check all" onclick="selectAllCheckbox('posted_by_box', true, true);"><i class="fa fa-plus-square-o"></i></a>
        <?php } ?>
        <a title="Clear" onclick="selectAllCheckbox('posted_by_box', false, true);"><i class="fa fa-minus-square-o"></i></a>
      </div>
    </div>
    <div class="panel-body panel-collapse collapse sidebar-panel-body <?php if (empty($filter['filter_posted_by_sel'])) { ?> in <?php } ?>" id="collapse_posted_by">
      <ul class="nav nav-list col-sm-6 pull-right">
        <li>
          <label class="checkbox-inline width-full">
            <input type="checkbox" value="dealer" name="posted_by[]" <?php if (in_array('dealer', $filter['filter_posted_by_sel'])) { ?> checked="true" <?php } ?>>
            <a>Dealer</a>
          </label>
        </li>
      </ul>
      <ul class="nav nav-list col-sm-6 pull-right">
        <li>
          <label class="checkbox-inline width-full">
            <input type="checkbox" value="owner" name="posted_by[]" <?php if (in_array('owner', $filter['filter_posted_by_sel'])) { ?> checked="true" <?php } ?>>
            <a>Owner</a>
          </label>
        </li>
      </ul>
    </div>
  </div>
  <?php if (!empty($filter['filter_give_for'])) { ?>
    <div class="panel panel-default" id="give_for_box">
      <div class="panel-heading">
        <a class="accordion-toggle <?php if (empty($filter['filter_give_for_sel'])) { ?> collapsed <?php } ?>" data-toggle="collapse" href="#collapse_give_for"><b>For</b></a>
        <div class="pull-right">
          <?php if (count($filter['filter_give_for']) == count($filter['filter_give_for_sel'])) { ?>
            <a title="Uncheck all" onclick="selectAllCheckbox('give_for_box', false, true);"><i class="fa fa-check-square-o"></i></a>
          <?php } else { ?>
            <a title="Check all" onclick="selectAllCheckbox('give_for_box', true, true);"><i class="fa fa-plus-square-o"></i></a>
          <?php } ?>
          <a title="Clear" onclick="selectAllCheckbox('give_for_box', false, true);"><i class="fa fa-minus-square-o"></i></a>
        </div>
      </div>
      <div class="panel-body panel-collapse collapse sidebar-panel-body <?php if (empty($filter['filter_give_for_sel'])) { ?> in <?php } ?>" id="collapse_give_for">
        <?php $count = 0 ?>
        <?php foreach ($filter['filter_give_for'] as $give_for) { ?>
          <ul class="nav nav-list col-sm-6 <?php if ($count % 2 != 0) { ?> pull-right <?php } ?>">
            <li>
              <label class="checkbox-inline width-full">
                <input type="checkbox" value="<?php echo $give_for['give_for_id']; ?>" name="give_for[]" <?php if (in_array($give_for['give_for_id'], $filter['filter_give_for_sel'])) { ?> checked="true" <?php } ?>>
                <a><?php echo $give_for['give_for_text']; ?></a>
              </label>
            </li>
          </ul>
          <?php $count++; ?>
        <?php } ?>
      </div>
    </div>
  <?php } ?>
  <?php if (!empty($filter['filter_peoples'])) { ?>
    <div class="panel panel-default" id="people_box">
      <div class="panel-heading">
        <a class="accordion-toggle <?php if (empty($filter['filter_peoples_sel'])) { ?> collapsed <?php } ?>" data-toggle="collapse" href="#collapse_people"><b>People</b></a>
        <div class="pull-right">
          <?php if (count($filter['filter_peoples']) == count($filter['filter_peoples_sel'])) { ?>
            <a title="Uncheck all" onclick="selectAllCheckbox('people_box', false, true);"><i class="fa fa-check-square-o"></i></a>
          <?php } else { ?>
            <a title="Check all" onclick="selectAllCheckbox('people_box', true, true);"><i class="fa fa-plus-square-o"></i></a>
          <?php } ?>
          <a title="Clear" onclick="selectAllCheckbox('people_box', false, true);"><i class="fa fa-minus-square-o"></i></a>
        </div>
      </div>
      <div class="panel-body panel-collapse collapse sidebar-panel-body <?php if (empty($filter['filter_peoples_sel'])) { ?> in <?php } ?>" id="collapse_people">
        <?php $count = 0 ?>
        <?php foreach ($filter['filter_peoples'] as $people) { ?>
          <ul class="nav nav-list col-sm-6 <?php if ($count % 2 != 0) { ?> pull-right <?php } ?>">
            <li>
              <label class="checkbox-inline width-full">
                <input type="checkbox" value="<?php echo $people['people_id']; ?>" name="peoples[]" <?php if (in_array($people['people_id'], $filter['filter_peoples_sel'])) { ?> checked="true" <?php } ?>>
                <a><?php echo $people['people_text']; ?></a>
              </label>
            </li>
          </ul>
          <?php $count++; ?>
        <?php } ?>
      </div>
    </div>
  <?php } ?>
</form>